package club.hicode.daydayup.redis.bf;

import bloomfilter.CanGenerateHashFrom;
import bloomfilter.mutable.BloomFilter;
import org.junit.Test;

/**
 * 布隆过滤器测试
 * @author Liu Chunfu
 * @date 2018-08-15 下午2:43
 **/
public class BFTest {

	/**
	 * 布隆过滤器测试 458
	 */
	@Test
	public void test1() {

		long start = System.currentTimeMillis();
		long expectedElements = 100;
		double falsePositiveRate = 0.1;
		BloomFilter<byte[]> bf = BloomFilter
				.apply(expectedElements, falsePositiveRate, CanGenerateHashFrom.CanGenerateHashFromByteArray$.MODULE$);

		for (int i = 0; i < 100000; i++) {
			bf.add((i + "").getBytes());
		}

		for (int i = 0; i < 100000; i++) {
			boolean b = bf.mightContain((i + "").getBytes());
			if (b == false) {
				System.out.println(i + " check false");
			}
		}
		bf.dispose();
		long end = System.currentTimeMillis();
		System.out.println(end - start);
	}
}
